﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace AppFrame
{
	class TextBoxTraceListener : StringWriter
	{
		public delegate void WriteDelegate(String myString);

		public void MyWriteDelegate(string s)
		{
			OutputTextBox.AppendText(s);
		}

		public TextBox OutputTextBox { get; set; }

		public TextBoxTraceListener(TextBox textBox)
		{
			OutputTextBox = textBox;
		}


		public override void Write(string value)
		{
			OutputTextBox.Invoke(new WriteDelegate(MyWriteDelegate), new object[] { value });
			//OutputTextBox.AppendText(value);
			base.Write(value);
		}

		public override void WriteLine(string value)
		{
			OutputTextBox.Invoke(new WriteDelegate(MyWriteDelegate), new object[]{value+NewLine});
			base.WriteLine(value);
		}
	}
}
